package com.noahplat.person.controller;

import com.noahplat.common.utils.Result;
import com.noahplat.person.pojo.Clitocybine;
import com.noahplat.person.service.ClitocybineService;
import com.sun.org.apache.regexp.internal.RE;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

/**
 * @ClassName: ClitocybineController
 * @Description: 荤素偏好controller
 * @Author 李景星
 * @Date 2021/3/8
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/clitocybine")
@Validated
public class ClitocybineController {

    @Autowired
    private ClitocybineService clitocybineService;


    /**
     * 获取荤素偏好
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:ClitocybineController:getClitocybine')")
    @GetMapping("/getClitocybine")
    public Result getClitocybine(){
        return clitocybineService.getClitocybine();
    }

    /**
     * 添加荤素偏好
     * @param clitocybine
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:ClitocybineController:addClitocybine')")
    @PostMapping("/addClitocybine")
    public Result addClitocybine(@RequestBody Clitocybine clitocybine){
        return clitocybineService.addClitocybine(clitocybine);
    }
    /**
     * 修改荤素偏好
     * @param clitocybine
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:ClitocybineController:updateClitocybine')")
    @PutMapping("/updateClitocybine")
    public Result updateClitocybine(@RequestBody Clitocybine clitocybine){
        return clitocybineService.updateClitocybine(clitocybine);
    }
    /**
     * 删除荤素偏好
     * @param id
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:ClitocybineController:delClitocybine')")
    @DeleteMapping("/delClitocybine")
    public Result delClitocybine(@NotNull(message = "ID不能为空 ") @Min(value = 1, message = "Id不能为空")Long id){
        return clitocybineService.delClitocybine(id);
    }
    /**
     * 分页获取荤素偏好
     * @param page
     * @param limit
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:ClitocybineController:getAdminClitocybine')")
    @GetMapping("/getAdminClitocybine")
    public Result getAdminClitocybine(@RequestParam(defaultValue = "1")Integer page,@RequestParam(defaultValue = "10")Integer limit){
        return clitocybineService.getAdminClitocybine(page, limit);
    }
    /**
     * 获取荤素偏好详细信息
     * @param id
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:ClitocybineController:getClitocybineById')")
    @GetMapping("/getClitocybineById")
    public Result getClitocybineById(@NotNull(message = "ID不能为空 ") @Min(value = 1, message = "Id不能为空")Long id){
        return clitocybineService.getClitocybineById(id);
    }
}
